package zhouzhouyongche.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import zhouzhouyongche.client_util.ErrorCode;
import zhouzhouyongche.model.Passenger;

@Repository
public class PassengerDao extends HibernateDao<Passenger> {

	public int deletePassenger(int passengerId) {
		boolean res = true;
		Passenger passenger = get(passengerId);
		try {
			delete(passenger);
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			res = false;
		}
		return res ? ErrorCode.SUCCESS : ErrorCode.ERROR_PASSENGER_DELETE;
	}

	public List<Passenger> getPassenger(int userId) {
		String hql = "select u.passengers "
				+ "from User as u "
				+ "where u.id = ?";
		Query q = getCurrentSession().createQuery(hql);
		q.setInteger(0, userId);
		return q.list();
	}

}
